// 应用程序入口文件。它使用 NestFactory 用来创建 Nest 应用实例
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { AllExceptionsFilter } from './any-exception.filter';
import { ConfigService } from '@nestjs/config';
import { MyLogger } from './app.logger';

declare const module: any;

async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    abortOnError: false,
    logger: new MyLogger(),
    cors: true
  });
  const configService = app.get(ConfigService);
  app.useGlobalFilters(new AllExceptionsFilter());
  const PORT = configService.get<number>('PORT')!;
  await app.listen(PORT);

  if (module.hot) {
    module.hot.accept();
    module.hot.dispose(() => app.close());
  }
}

bootstrap();
